package cn.lg.soar.system.biz.modules.general.service;

import cn.lg.soar.system.api.enums.ThumbnailSizeEnum;
import cn.lg.soar.system.biz.filetemplate.FileTemplateManager;
import cn.lg.soar.system.biz.util.FileAccessTokenUtils;
import com.amazonaws.services.s3.model.S3Object;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * @author luguoxiang 469599794@qq.com
 * @Date: 2024/6/1 13:17
 * 开源项目：https://gitee.com/lgx1992/lg-soar 求star！请给我star！请帮我点个star！
 */
public class FileAccessService {

    @Autowired
    private FileTemplateManager uploadTemplateManager;

    /**
     * 临时路径访问
     * @param storageId
     * @param directory
     * @param fileInfo
     * @param size
     * @return
     */
    public S3Object tempUrlAccess(Integer storageId, String directory, String fileInfo, ThumbnailSizeEnum size) {
        String filename = FileAccessTokenUtils.parseTempUrlFileInfo(fileInfo);
        return uploadTemplateManager.getTemplate(storageId).getObject(filename);
    }

    /**
     * 匿名访问
     * @param storageId
     * @param directory
     * @param fileInfo
     * @param size
     * @return
     */
    public S3Object anonUrlAccess(int storageId, String directory, String fileInfo, ThumbnailSizeEnum size) {
        String filename = FileAccessTokenUtils.parseAnonUrlFileInfo(fileInfo);
        return uploadTemplateManager.getTemplate(storageId)
                .getObject(filename);
    }

    /**
     * 代理访问
     * @param storageId
     * @param directory
     * @param filename
     * @param size
     * @return
     */
    public S3Object proxyUrlAccess(Integer storageId, String directory, String filename, ThumbnailSizeEnum size) {
        return uploadTemplateManager.getTemplate(storageId)
                .getObject(filename);
    }

    /**
     * 获取重定向路径
     * @param storageId
     * @param directory
     * @param filename
     * @param size
     * @return
     */
    public String getRedirectUrl(int storageId, String directory, String filename, ThumbnailSizeEnum size) {
        return "";
    }

}
